package controller.link.game;

import view.client.Console;
import model.Hearer;
import java.io.Serializable;
import controller.Link;
import controller.link.RefreshGameData;
import model.game.Item;
import model.game.Place;
import model.game.Scenario;
import model.Attendant;
import model.Server;
import model.game.Location;

public class PickItem implements Link, Serializable {
    private String nameItem;

    public PickItem(Hearer h, String nameItem) {
        this.nameItem = nameItem;
        h.send((Link) this);
    }

    @Override
    public void serverUse(Server server, Attendant at) {
        Location o = server.getWorld().getMap().whereIsPlayer(at.getUser().getName());
        for (int i=0; i<o.getItems().size(); i++){
                if (o.getItems().get(i).getName().equals(nameItem)){
                    Item item = o.getItems().get(i);
                    at.getUser().getPlayer().addItem(item.changeOwner(at.getUser().getPlayer()));
                    o.removeItem(nameItem);
                }
            }       
        RefreshGameData rgd = new RefreshGameData();
        rgd.serverUse(server, at);
    }

    @Override
    public void clientUse(Console console) {
    }
}
